/////////////////////////////////////////
// Controller box bottom
//
// Author:    Eric Lind
// Revision:  0
// Rev. Date: 2013-08-11
// 
// History:
// 
/////////////////////////////////////////

//Parameters (changable)
thick=2;								//Thickness of bracket material
radius=2;							//Radies on bracker corners
holes=4.1;							//Diameter of holes on bracket
mat=20;								//Material size bracket should fit on
res=100;    							//Resulotion of all arcs
b_width=70;							//Box width
b_length=120;						//Box length
b_height=30;							//Box inner heigth
b_thick=3;							//Box material thicknes
b_i_radius=4;						//Inner radies of corners in box
b_o_radius=b_i_radius+b_thick;		//Outer radies of box
lid_overlap=2;						//Height of overlap for lid
s_radius=3;							//Size of studs
s_height=4;							//Height of studs


//Model, do not edit! (Exept for stud coordinates at bottom of code)
union(){
	difference() {
		union() {
			//Bracket
			translate([radius,(b_width/2)-(mat/2)-thick,-mat]) {cube([b_length-(2*radius), mat+(2*thick), mat]);}
			translate([0,(b_width/2)-(mat/2)-thick,-mat+radius]) {cube([b_length, mat+(2*thick), mat]);}
			translate([0,(b_width/2)-(mat/2)-thick-radius,-radius]) {cube([b_length,radius,radius]);}
			translate([0,(b_width/2)+(mat/2)+thick,-radius]) {cube([b_length,radius,radius]);}
		
			//Bracket Corners
			 translate([radius, (b_width/2)-(mat/2)-thick, -mat+radius]) rotate([-90,0,0]) {cylinder(r=radius, h=(2*thick)+mat, $fn=res);}
			translate([b_length-radius, (b_width/2)-(mat/2)-thick, -mat+radius]) rotate([-90,0,0]) {cylinder(r=radius, h=(2*thick)+mat, $fn=res);}

			//Box corners
			translate([b_o_radius,b_o_radius,0]) {cylinder(r=b_o_radius, h=b_height+b_thick-lid_overlap, $fn=res);}
			translate([b_length-b_o_radius,b_o_radius,0]) {cylinder(r=b_o_radius, h=b_height+b_thick-lid_overlap, $fn=res);}
			translate([b_o_radius,b_width-b_o_radius,0]) {cylinder(r=b_o_radius, h=b_height+b_thick-lid_overlap, $fn=res);}
			translate([b_length-b_o_radius,b_width-b_o_radius,0]) {cylinder(r=b_o_radius, h=b_height+b_thick-lid_overlap, $fn=res);}
		
			//Box lid overlap corners
			translate([b_o_radius,b_o_radius,0]) {cylinder(r=b_o_radius-(b_thick/2), h=b_height+b_thick, $fn=res);}
			translate([b_length-b_o_radius,b_o_radius,0]) {cylinder(r=b_o_radius-(b_thick/2), h=b_height+b_thick, $fn=res);}
			translate([b_o_radius,b_width-b_o_radius,0]) {cylinder(r=b_o_radius-(b_thick/2), h=b_height+b_thick, $fn=res);}
			translate([b_length-b_o_radius,b_width-b_o_radius,0]) {cylinder(r=b_o_radius-(b_thick/2), h=b_height+b_thick, $fn=res);}
		
			//Box
			translate([b_o_radius,0,0]) {cube([b_length-(2*b_o_radius),b_width,b_height+b_thick-lid_overlap]);}
			translate([0,b_o_radius,0]){cube([b_length,b_width-(2*b_o_radius),b_height+b_thick-lid_overlap]);}
		
			//Box lid overlap
			translate([b_o_radius,(b_thick/2),0]) {cube([b_length-(2*(b_o_radius-(b_thick/2)))-b_thick,b_width-b_thick,b_height+b_thick]);}
			translate([(b_thick/2),b_o_radius,0]) {cube([b_length-b_thick,b_width-(2*(b_o_radius-(b_thick/2)))-b_thick,b_height+b_thick]);}
			}
		//Bracket
		translate([-1,(b_width/2)-(mat/2),-mat-1]) { cube([b_length+2,mat,mat+1]);}
		translate([-1,(b_width/2)-(mat/2)-thick-radius, -radius]) rotate([0,90,0]) {cylinder(r=radius, h=b_length+2, $fn=res);}
		translate([-1,(b_width/2)+(mat/2)+thick+radius, -radius]) rotate([0,90,0]) {cylinder(r=radius, h=b_length+2, $fn=res);}

		//Bracket holes
		translate([mat/2,0,-(mat/2)]) rotate([-90,0,0]) {cylinder(r=holes/2, h=b_width, $fn=res);}
		translate([b_length-(mat/2),0,-(mat/2)]) rotate([-90,0,0]) {cylinder(r=holes/2, h=b_width, $fn=res);}
		translate([b_length/2,0,-(mat/2)]) rotate([-90,0,0]) {cylinder(r=holes/2, h=b_width, $fn=res);}

		//Inside
		translate([b_o_radius,b_o_radius,b_thick]) {cylinder(r=b_o_radius-b_thick, h=b_height+b_thick, $fn=res);}
		translate([b_length-b_o_radius,b_o_radius,b_thick]) {cylinder(r=b_o_radius-b_thick, h=b_height+b_thick, $fn=res);}
		translate([b_o_radius,b_width-b_o_radius,b_thick]) {cylinder(r=b_o_radius-b_thick, h=b_height+b_thick, $fn=res);}
		translate([b_length-b_o_radius,b_width-b_o_radius,b_thick]) {cylinder(r=b_o_radius-b_thick, h=b_height+b_thick, $fn=res);}
		translate([b_o_radius,b_thick,b_thick]) {cube([b_length-(2*b_o_radius),b_width-(2*b_thick),b_height+b_thick]);}
		translate([b_thick,b_o_radius,b_thick]){cube([b_length-(2*b_thick),b_width-(2*b_o_radius),b_height+b_thick]);}
	}
	//Studs to screw controller to (Edit coordinates to your controller holes)
	translate([b_o_radius+10,b_o_radius+10,0]) {cylinder(r=s_radius, h=s_height+b_thick, $fn=res);}
	translate([b_length-b_o_radius-10,b_o_radius+10,0]) {cylinder(r=s_radius, h=s_height+b_thick, $fn=res);}
	translate([b_o_radius+10,b_width-b_o_radius-10,0]) {cylinder(r=s_radius, h=s_height+b_thick, $fn=res);}
	translate([b_length-b_o_radius-10,b_width-b_o_radius-10,0]) {cylinder(r=s_radius, h=s_height+b_thick, $fn=res);}
}